package suspect

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/model/suspect"
	suspectReq "github.com/flipped-aurora/gin-vue-admin/server/model/suspect/request"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type CasSuspectsApi struct{}

// CreateCasSuspects 创建casSuspects表
// @Tags CasSuspects
// @Summary 创建casSuspects表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body suspect.CasSuspects true "创建casSuspects表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /casSuspects/createCasSuspects [post]
func (casSuspectsApi *CasSuspectsApi) CreateCasSuspects(c *gin.Context) {
	var casSuspects suspect.CasSuspects
	err := c.ShouldBindJSON(&casSuspects)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = casSuspectsService.CreateCasSuspects(&casSuspects)
	if err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("创建成功", c)
}

// DeleteCasSuspects 删除casSuspects表
// @Tags CasSuspects
// @Summary 删除casSuspects表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body suspect.CasSuspects true "删除casSuspects表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /casSuspects/deleteCasSuspects [delete]
func (casSuspectsApi *CasSuspectsApi) DeleteCasSuspects(c *gin.Context) {
	ID := c.Query("ID")
	err := casSuspectsService.DeleteCasSuspects(ID)
	if err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteCasSuspectsByIds 批量删除casSuspects表
// @Tags CasSuspects
// @Summary 批量删除casSuspects表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /casSuspects/deleteCasSuspectsByIds [delete]
func (casSuspectsApi *CasSuspectsApi) DeleteCasSuspectsByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	err := casSuspectsService.DeleteCasSuspectsByIds(IDs)
	if err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateCasSuspects 更新casSuspects表
// @Tags CasSuspects
// @Summary 更新casSuspects表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body suspect.CasSuspects true "更新casSuspects表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /casSuspects/updateCasSuspects [put]
func (casSuspectsApi *CasSuspectsApi) UpdateCasSuspects(c *gin.Context) {
	var casSuspects suspect.CasSuspects
	err := c.ShouldBindJSON(&casSuspects)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = casSuspectsService.UpdateCasSuspects(casSuspects)
	if err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindCasSuspects 用id查询casSuspects表
// @Tags CasSuspects
// @Summary 用id查询casSuspects表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query suspect.CasSuspects true "用id查询casSuspects表"
// @Success 200 {object} response.Response{data=suspect.CasSuspects,msg=string} "查询成功"
// @Router /casSuspects/findCasSuspects [get]
func (casSuspectsApi *CasSuspectsApi) FindCasSuspects(c *gin.Context) {
	ID := c.Query("ID")
	recasSuspects, err := casSuspectsService.GetCasSuspects(ID)
	if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:"+err.Error(), c)
		return
	}
	response.OkWithData(recasSuspects, c)
}

// GetCasSuspectsList 分页获取casSuspects表列表
// @Tags CasSuspects
// @Summary 分页获取casSuspects表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query suspectReq.CasSuspectsSearch true "分页获取casSuspects表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /casSuspects/getCasSuspectsList [get]
func (casSuspectsApi *CasSuspectsApi) GetCasSuspectsList(c *gin.Context) {
	var pageInfo suspectReq.CasSuspectsSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := casSuspectsService.GetCasSuspectsInfoList(pageInfo)
	if err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败:"+err.Error(), c)
		return
	}
	response.OkWithDetailed(response.PageResult{
		List:     list,
		Total:    total,
		Page:     pageInfo.Page,
		PageSize: pageInfo.PageSize,
	}, "获取成功", c)
}

// GetCasSuspectsDataSource 获取CasSuspects的数据源
// @Tags CasSuspects
// @Summary 获取CasSuspects的数据源
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "查询成功"
// @Router /casSuspects/getCasSuspectsDataSource [get]
func (casSuspectsApi *CasSuspectsApi) GetCasSuspectsDataSource(c *gin.Context) {
	// 此接口为获取数据源定义的数据
	dataSource, err := casSuspectsService.GetCasSuspectsDataSource()
	if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:"+err.Error(), c)
		return
	}
	response.OkWithData(dataSource, c)
}

// GetCasSuspectsPublic 不需要鉴权的casSuspects表接口
// @Tags CasSuspects
// @Summary 不需要鉴权的casSuspects表接口
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /casSuspects/getCasSuspectsPublic [get]
func (casSuspectsApi *CasSuspectsApi) GetCasSuspectsPublic(c *gin.Context) {
	// 此接口不需要鉴权
	// 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
	casSuspectsService.GetCasSuspectsPublic()
	response.OkWithDetailed(gin.H{
		"info": "不需要鉴权的casSuspects表接口信息",
	}, "获取成功", c)
}
